﻿@model CustomerModel

@{
    var parentModel = ViewData["Parent"] as CustomerListModel;
}

<datagrid id="customers-grid"
          allow-resize="true"
          allow-row-selection="true"
          allow-column-reordering="true"
          onrowclass="customersGrid_onRowClass">
    <datasource read="@Url.Action("CustomerList")" delete="@Url.Action("CustomerDelete")" />
    <paging position="Bottom" show-size-chooser="true" />
    <sorting enabled="true" allow-unsort="true" allow-multisort="false">
        <sort by="CreatedOn" by-entity-member="CreatedOnUtc" descending="true" />
    </sorting>
    <toolbar>
        <toolbar-group>
            <button datagrid-action="DataGridToolAction.ToggleSearchPanel" class="btn btn-light btn-icon">
                <i class="fa fa-fw fa-filter"></i>
            </button>
        </toolbar-group>
        <toolbar-group>
            <a asp-action="Create" class="btn btn-primary btn-flat no-anims mr-auto">
                <i class="fa fa-plus"></i>
                <span>@T("Admin.Common.AddNew")...</span>
            </a>
        </toolbar-group>
        <zone name="datagrid_toolbar_alpha"></zone>
        <toolbar-group class="omega"></toolbar-group>
        <zone name="datagrid_toolbar_omega"></zone>
        <toolbar-group>
            <button datagrid-action="DataGridToolAction.DeleteSelectedRows" type="button" class="btn btn-danger btn-flat">
                <i class="far fa-trash-can"></i>
                <span>@T("Admin.Common.Delete.Selected")</span>
            </button>
        </toolbar-group>
    </toolbar>
    <search-panel>
        <partial name="Grids/_Grid.Customers.Search" model="parentModel" />
    </search-panel>
    <columns>
        <column for="Id" visible="false" type="string" />
        <column for="Email" hideable="false">
            <display-template>
                <a :href="item.row.EditUrl" class="text-truncate">
                    {{ item.value }}
                </a>
            </display-template>
        </column>
        @if (parentModel.UsernamesEnabled)
        {
            <column for="Username" />
        }

        <column for="FullName" />
        <column for="CustomerRoleNames" sortable="false" />

        @if (parentModel.CompanyEnabled)
        {
            <column for="Company" />
        }
        @if (parentModel.PhoneEnabled)
        {
            <column for="Phone" sortable="false" />
        }
        @if (parentModel.ZipPostalCodeEnabled)
        {
            <column for="ZipPostalCode" sortable="false" />
        }
        <column for="Active" halign="center" />
        <column for="CreatedOn" entity-member="CreatedOnUtc" />
        <column for="LastActivityDate" entity-member="LastActivityDateUtc" />

        <!-- Initially hidden columns -->
        <column for="IsTaxExempt" halign="center" visible="false" />
        <column for="LastIpAddress" visible="false" />
        <column for="CustomerNumber" visible="false" />
        <column for="DateOfBirth" visible="false" sortable="false" />
        <column for="Gender" visible="false" />
        <column for="VatNumber" visible="false" sortable="false" />
        <column for="LimitedToStores" visible="!parentModel.IsSingleStoreMode" readonly="true" halign="center" />
    </columns>
</datagrid>

<script sm-target-zone="scripts" data-origin="customers-grid">
    function customersGrid_onRowClass(row) {
        return {
            "text-muted": !row.Active
        };
    }
</script>